using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency.Suite;

namespace Konst3d.Efficiency.Suite.SparsedBinary
{
    internal interface INoteStorage
    {
        void UpdateTitle   (int id, string title);
        void UpdateText    (int id, string text);
        void UpdateCreated (int id, DateTime createdDate);
    }

    internal class Note: INote
    {
        #region INote Members

        public int ID
        {
            get
            {
                return _id;
            }
        }

        public string Title
        {
            get
            {
                return _title;
            }
            set
            {
                _storage.UpdateTitle(_id, value);
                _title = value;
            }
        }

        public string Text
        {
            get
            {
                return _text;
            }
            set
            {
                _storage.UpdateText(_id, value);
                _text = value;
            }
        }

        public DateTime Created
        {
            get
            {
                return _created;
            }
        }

        #endregion

        #region Constructor

        public Note(INoteStorage storage, int id, string title, string text, DateTime created)
        {
            Contract.Requires(storage != null);

            _storage = storage;
            _id = id;
            _title = title;
            _text = text;
            _created = created;
        }

        #endregion // Constructor

        #region Fields

        private INoteStorage _storage;
        private int _id;
        private string _title;
        private string _text;
        private DateTime _created;

        #endregion // Fields
    }
}
